package com.wc.codeforces.前缀和与差分.前缀和.Decode;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/7/28 10:50
 * @description https://codeforces.com/contest/1996/problem/E
 */

public class Main {
    /**
     * 思路：
     * 求一个区间是否0和1相同, 相当于求前缀和是否为0, 将s[i] = '0] => s[i] = -1
     * 如何快速求出[x, y] 我们可以固定x, 观察后面有多少个符合的y, r >= y那就说明有 n - y + 1组数对
     * 为了方便起见, 我们看前面有多少个x满足
     * pre[x - 1] = pre[y]
     * 需要一个计数器
     * 思路明确开始写代码
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010, P = (int) 1e9 + 7;
    static char[] s;
    static int[] pre = new int[N];
    static int[] cnt = new int[N + N];

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            s = (" " + sc.next()).toCharArray();
            int n = s.length - 1;
            Arrays.fill(cnt, 0, n * 2 + 1, 0);
            for (int i = 1; i <= n; i++) pre[i] = (s[i] == '1' ? 1 : -1) + pre[i - 1];
            long res = 0;
            // pre[i] = 0, 自己算一个 => cnt[pre[i] + n] = 1
            cnt[n] = 1;
            for (int i = 1; i <= n; i++) {
                res = (res + (long) (n - i + 1) * cnt[pre[i] + n]) % P;
                cnt[pre[i] + n] = (cnt[pre[i] + n] + i + 1) % P;
            }
            out.println(res);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
